/**
 * Description:
 * Class Name:Composite
 * Date:2022/1/13 10:16
 *
 * @author LTisme
 * @version JAVA17
 */
//package 疯狂Java讲义.第5章_面向对象_上.多态.第5_8.继承与组合;

class Animal{
    private void beat(){
        System.out.println("心脏跳动...");
    }
    public void breathe(){
        beat();
        System.out.println("吸气，吐气，呼吸中...");
    }
}

class Bird{
    private Animal a;
    public Bird(Animal a){
        this.a = a;
    }
    public void breathe(){
        a.breathe();
    }
    public void fly(){
        System.out.println("小鸟在天空自由地飞翔...");
    }
}

class Wolf{
    private Animal a;
    public Wolf(Animal a){
        this.a = a;
    }
    public void breathe(){
        a.breathe();
    }
    public void run(){
        System.out.println("小狼在陆地快速地奔跑...");
    }
}

public class Composite {
    public static void main(String[] args) {
        var a1 = new Animal();
        var b = new Bird(a1);
        b.breathe();
        b.fly();

//        var a2 = new Animal();
        var w = new Wolf(a1);
        w.breathe();
        w.run();
    }
}
